package com.lagou.edu.mvcframework.listener;

import com.lagou.edu.mvcframework.filter.LgSecurityFilter;

import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.EnumSet;

public class LgServletContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();

        LgSecurityFilter lgSecurityFilter = new LgSecurityFilter();
        javax.servlet.FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("lgSecurityFilter", lgSecurityFilter);
        filterRegistration.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST),
                false,
                "lgoumvc");
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
